import django_filters
from rest_framework import filters
from django_filters.rest_framework import DjangoFilterBackend

from merchants.models import *
from activities.models import *
from goods.models import *


class MerchantUserFilter(django_filters.rest_framework.FilterSet):

    is_psbc_card = django_filters.BaseInFilter(field_name='is_psbc_card', lookup_expr='in')
    lucky_bag_max = django_filters.NumberFilter(field_name="lucky_bag", lookup_expr='lte')
    lucky_bag_min = django_filters.NumberFilter(field_name="lucky_bag", lookup_expr='gte')

    class Meta:
        model = MerchantUser
        fields = ('is_psbc_card', 'lucky_bag_max', 'lucky_bag_min')


class MerchantFilter(django_filters.rest_framework.FilterSet):
    '''商户过滤'''

    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')
    is_mall = django_filters.BaseInFilter(field_name='is_mall', lookup_expr='in')
    applyment_state = django_filters.BaseInFilter(field_name='applyment_state', lookup_expr='in')
    verify_state = django_filters.BaseInFilter(field_name='verify_state', lookup_expr='in')
    subject_type = django_filters.BaseInFilter(field_name='subject_type', lookup_expr='in')
    merchantuser_id = django_filters.BaseInFilter(field_name='merchantuser_id', lookup_expr='in')

    class Meta:
        model = Merchant
        fields = ('create_time_begin', 'create_time_end', 'verify_state', 'is_mall', 'applyment_state', 'subject_type', 'merchantuser_id')


class LuckyBagChildActivityDataFilter(django_filters.rest_framework.FilterSet):

    lucky_status = django_filters.BaseInFilter(field_name='lucky_status', lookup_expr='in')
    luckybagchildactivity_id = django_filters.BaseInFilter(field_name='luckybagchildactivity_id', lookup_expr='in')
    merchantuser_id = django_filters.BaseInFilter(field_name='merchantuser_id', lookup_expr='in')
    lucky_bag_max = django_filters.NumberFilter(field_name="lucky_bag", lookup_expr='lte')
    lucky_bag_min = django_filters.NumberFilter(field_name="lucky_bag", lookup_expr='gte')
    received_time_begin = django_filters.DateTimeFilter(field_name="received_time__date", lookup_expr='gte')
    received_time_end = django_filters.DateTimeFilter(field_name="received_time__date", lookup_expr='lte')

    class Meta:
        model = LuckyBagChildActivityData
        fields = ('lucky_status', 'lucky_bag_max', 'lucky_bag_min', 'luckybagchildactivity_id', 'received_time_begin', 'received_time_end', 'merchantuser_id')


class LuckyBagRecordFilter(django_filters.rest_framework.FilterSet):

    operate_type = django_filters.BaseInFilter(field_name='operate_type', lookup_expr='in')
    merchantuser_id = django_filters.BaseInFilter(field_name='merchantuser_id', lookup_expr='in')
    lucky_bag_max = django_filters.NumberFilter(field_name="lucky_bag", lookup_expr='lte')
    lucky_bag_min = django_filters.NumberFilter(field_name="lucky_bag", lookup_expr='gte')
    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')

    class Meta:
        model = LuckyBagRecord
        fields = ('operate_type', 'lucky_bag_max', 'lucky_bag_min', 'create_time_begin', 'create_time_end', 'merchantuser_id')


class MerchantEnterQuestFilter(django_filters.rest_framework.FilterSet):

    file_status = django_filters.BaseInFilter(field_name='file_status', lookup_expr='in')

    class Meta:
        model = MerchantEnterQuest
        fields = ('file_status',)


class MerchantNFCDeviceTradeFilter(django_filters.rest_framework.FilterSet):

    trade_time_begin = django_filters.DateTimeFilter(field_name="trade_time__date", lookup_expr='gte')
    trade_time_end = django_filters.DateTimeFilter(field_name="trade_time__date", lookup_expr='lte')
    total_amount_max = django_filters.NumberFilter(field_name="total_amount", lookup_expr='lte')
    total_amount_min = django_filters.NumberFilter(field_name="total_amount", lookup_expr='gte')

    class Meta:
        model = MerchantNFCDeviceTrade
        fields = ('trade_time_begin', 'trade_time_end', 'total_amount_max', 'total_amount_min')


class MerchantMonthlyBillFilter(django_filters.rest_framework.FilterSet):

    merchant_id = django_filters.BaseInFilter(field_name='merchant_id', lookup_expr='in')
    settlement_amount_min = django_filters.NumberFilter(field_name="settlement_amount", lookup_expr='gte')
    settlement_amount_max = django_filters.NumberFilter(field_name="settlement_amount", lookup_expr='lte')
    business_no = django_filters.BaseInFilter(field_name='merchant__wyfMerchantID', lookup_expr='in')
    receipts_time_begin = django_filters.DateTimeFilter(field_name="receipts_time__date", lookup_expr='gte')
    receipts_time_end = django_filters.DateTimeFilter(field_name="receipts_time__date", lookup_expr='lte')

    class Meta:
        model = MerchantMonthlyBill
        fields = ('settlement_amount_min', 'settlement_amount_min', 'merchant_id', 'business_no', 'receipts_time_begin', 'receipts_time_end')


class MerchantEightEightActivityFilter(django_filters.rest_framework.FilterSet):

    activity_status = django_filters.BaseInFilter(field_name='activity_status', lookup_expr='in')
    activity_type = django_filters.BaseInFilter(field_name='activity_type', lookup_expr='in')

    class Meta:
        model = MerchantEightEightActivity
        fields = ('activity_status', 'activity_type')


class MerchantEightEightActivityPrizeFilter(django_filters.rest_framework.FilterSet):

    activity_id = django_filters.BaseInFilter(field_name='activity_id', lookup_expr='in')

    class Meta:
        model = MerchantEightEightActivityPrize
        fields = ('activity_id', )


class MerchantBusinessQRCodeVisitFilter(django_filters.rest_framework.FilterSet):
    '''添加用户申请单过滤'''

    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')
    qrcode_id = django_filters.BaseInFilter(field_name='qrcode_id', lookup_expr='in')

    class Meta:
        model = MerchantBusinessQRCodeVisit
        fields = ('create_time_begin', 'create_time_end', 'qrcode_id')


class MerchantBusinessQRCodeFilter(django_filters.rest_framework.FilterSet):

    is_bind = django_filters.BaseInFilter(field_name='is_bind', lookup_expr='in')
    is_c_bind = django_filters.BaseInFilter(field_name='is_c_bind', lookup_expr='in')
    bind_time_begin = django_filters.DateTimeFilter(field_name="bind_time__date", lookup_expr='gte')
    bind_time_end = django_filters.DateTimeFilter(field_name="bind_time__date", lookup_expr='lte')

    class Meta:
        model = MerchantBusinessQRCode
        fields = ('is_bind', 'bind_time_begin', 'bind_time_end', 'is_c_bind')


class MerchantEightEightDrawFilter(django_filters.rest_framework.FilterSet):

    state = django_filters.BaseInFilter(field_name='state', lookup_expr='in')
    activity_id = django_filters.BaseInFilter(field_name='activity_id', lookup_expr='in')
    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')
    amount_min = django_filters.NumberFilter(field_name="amount", lookup_expr='gte')
    amount_max = django_filters.NumberFilter(field_name="amount", lookup_expr='lte')

    class Meta:
        model = MerchantEightEightDraw
        fields = ('state', 'create_time_begin', 'create_time_end', 'amount_min', 'amount_max', 'activity_id')


class MerchantBillFilter(django_filters.rest_framework.FilterSet):
    '''商户账单'''

    receipts_time_begin = django_filters.DateTimeFilter(field_name="receipts_time__date", lookup_expr='gte')
    receipts_time_end = django_filters.DateTimeFilter(field_name="receipts_time__date", lookup_expr='lte')
    receipts_time = django_filters.DateTimeFilter(field_name="receipts_time__date", lookup_expr='lte')
    bill_state = django_filters.BaseInFilter(field_name='bill_state', lookup_expr='in')
    payable_amount_min = django_filters.NumberFilter(field_name="payable_amount", lookup_expr='gte')
    payable_amount_max = django_filters.NumberFilter(field_name="payable_amount", lookup_expr='lte')
    level_id = django_filters.BaseInFilter(field_name='merchant__level_id', lookup_expr='in')
    merchant_id = django_filters.BaseInFilter(field_name='merchant_id', lookup_expr='in')
    channel_id = django_filters.BaseInFilter(field_name='channel_id', lookup_expr='in')
    bill_type = django_filters.BaseInFilter(field_name='bill_type', lookup_expr='in')

    class Meta:
        model = MerchantBill
        fields = ('receipts_time_begin', 'receipts_time_end', 'bill_state', 'payable_amount_min', 'payable_amount_max', 'level_id', 'merchant_id', 'receipts_time', 'channel_id',
                  'bill_type')


class MerchantEightEightDrawKeguanFilter(django_filters.rest_framework.FilterSet):
    '''商户达标奖客管推送记录过滤'''
    push_status = django_filters.BaseInFilter(field_name='push_status', lookup_expr='in')
    activity_id = django_filters.BaseInFilter(field_name='draw__activity_id', lookup_expr='in')
    push_time_begin = django_filters.DateTimeFilter(field_name="push_time__date", lookup_expr='gte')
    push_time_end = django_filters.DateTimeFilter(field_name="push_time__date", lookup_expr='lte')

    class Meta:
        model = MerchantEightEightDrawKeguan
        fields = ('push_status', 'activity_id', 'push_time_begin', 'push_time_end')



class WaivePaymentActivityFilter(django_filters.rest_framework.FilterSet):

    activity_state = django_filters.BaseInFilter(field_name='activity_state', lookup_expr='in')

    class Meta:
        model = WaivePaymentActivity
        fields = ('activity_state',)


class WaivePaymentAdvanceFilter(django_filters.rest_framework.FilterSet):

    waivepaymentactivity_id = django_filters.BaseInFilter(field_name='waivepaymentactivity_id', lookup_expr='in')
    operate_type = django_filters.BaseInFilter(field_name='operate_type', lookup_expr='in')

    class Meta:
        model = WaivePaymentAdvance
        fields = ('waivepaymentactivity_id', 'operate_type')


class WaivePaymentMerchantKeguanFilter(django_filters.rest_framework.FilterSet):
    '''月月邮免单-客管推送过滤'''
    push_status = django_filters.BaseInFilter(field_name='push_status', lookup_expr='in')
    activity_id = django_filters.BaseInFilter(field_name='payment_id', lookup_expr='in')
    push_time_begin = django_filters.DateTimeFilter(field_name="push_time__date", lookup_expr='gte')
    push_time_end = django_filters.DateTimeFilter(field_name="push_time__date", lookup_expr='lte')

    class Meta:
        model = WaivePaymentMerchantKeguan
        fields = ('push_status', 'activity_id', 'push_time_begin', 'push_time_end')





class WaivePaymentMerchantFilter(django_filters.rest_framework.FilterSet):

    payment_state = django_filters.BaseInFilter(field_name='payment_state', lookup_expr='in')
    waivepaymentadvance_id = django_filters.BaseInFilter(field_name='waivepaymentadvance_id', lookup_expr='in')
    waivepaymentactivity_id = django_filters.BaseInFilter(field_name='waivepaymentactivity_id', lookup_expr='in')

    class Meta:
        model = WaivePaymentMerchant
        fields = ('payment_state', 'waivepaymentadvance_id', 'waivepaymentactivity_id')


class WaivePaymentOrderFilter(django_filters.rest_framework.FilterSet):

    waivepaymentmerchant_id = django_filters.BaseInFilter(field_name='waivepaymentmerchant_id', lookup_expr='in')
    waivepaymentactivity_id = django_filters.BaseInFilter(field_name='waivepaymentactivity_id', lookup_expr='in')
    is_hit = django_filters.BaseInFilter(field_name='is_hit', lookup_expr='in')

    class Meta:
        model = WaivePaymentOrder
        fields = ('waivepaymentmerchant_id', 'waivepaymentactivity_id', 'is_hit')


class MerchantSettlementRecordFilter(django_filters.rest_framework.FilterSet):

    settlement_time_begin = django_filters.DateTimeFilter(field_name="settlement_time__date", lookup_expr='gte')
    settlement_time_end = django_filters.DateTimeFilter(field_name="settlement_time__date", lookup_expr='lte')
    settlement_time = django_filters.DateTimeFilter(field_name="settlement_time__date", lookup_expr='gt')
    status = django_filters.BaseInFilter(field_name='status', lookup_expr='in')
    channel_id = django_filters.BaseInFilter(field_name='channel_id', lookup_expr='in')
    is_bind = django_filters.BaseInFilter(field_name='is_bind', lookup_expr='in')
    merchant_id = django_filters.BaseInFilter(field_name='merchant_id', lookup_expr='in')

    class Meta:
        model = MerchantSettlementRecord
        fields = ('settlement_time_begin', 'settlement_time_end', 'status', 'channel_id', 'is_bind', 'settlement_time', 'merchant_id')


class MerchantBankQRCodeQuestFilter(django_filters.rest_framework.FilterSet):

    file_type = django_filters.BaseInFilter(field_name='file_type', lookup_expr='in')
    file_status = django_filters.BaseInFilter(field_name='file_status', lookup_expr='in')

    class Meta:
        model = MerchantBankQRCodeQuest
        fields = ('file_type', 'file_status')


class MerchantBankQRCodeFilter(django_filters.rest_framework.FilterSet):

    is_download = django_filters.BaseInFilter(field_name='is_download', lookup_expr='in')

    class Meta:
        model = MerchantBankQRCode
        fields = ('is_download', )


class MerchantBankQRCodeBindDataFilter(django_filters.rest_framework.FilterSet):

    card_type = django_filters.BaseInFilter(field_name='card_type', lookup_expr='in')
    is_first = django_filters.BaseInFilter(field_name='is_first', lookup_expr='in')
    bank_qrcode_id = django_filters.BaseInFilter(field_name='bank_qrcode_id', lookup_expr='in')
    bind_time_begin = django_filters.DateTimeFilter(field_name="bind_time__date", lookup_expr='gte')
    bind_time_end = django_filters.DateTimeFilter(field_name="bind_time__date", lookup_expr='lte')

    class Meta:
        model = MerchantBankQRCodeBindData
        fields = ('card_type', 'is_first', 'bind_time_begin', 'bind_time_end', 'bank_qrcode_id')


class MErchantBankQPCodeStatisticsFilter(django_filters.rest_framework.FilterSet):

    bank_qrcode_id = django_filters.BaseInFilter(field_name='bank_qrcode_id', lookup_expr='in')
    bind_time_begin = django_filters.DateTimeFilter(field_name="bind_time__date", lookup_expr='gte')
    bind_time_end = django_filters.DateTimeFilter(field_name="bind_time__date", lookup_expr='lte')

    class Meta:
        model = MErchantBankQPCodeStatistics
        fields = ('bind_time_begin', 'bind_time_end', 'bank_qrcode_id')